﻿namespace Base
{
    /// <summary>
    /// 数据集
    /// </summary>
    namespace Data
    {
        using System;
        using System.Collections.Generic;
        using System.IO;
        using System.Text;
        using System.Threading;
        using Base.Custom;
        using UnityEngine;
        using System.Linq;
        #region Json解析类集合
        /// <summary>
        /// FXB JSON解析类
        /// </summary>
        [Serializable]
        class FBXinfo : ISerializationCallbackReceiver
        {
            public string name;
            public string path;
            public void OnAfterDeserialize() { }
            public void OnBeforeSerialize() { }
        }
        [Serializable]
       public class Message
        {
            public string key;
            public Property[] property;
            public Maintain[] maintain;

        }
        [Serializable]
        public class Property
        {
            public string name;
            public string value;
            public Property() { }
            public Property(string _name, string _value)
            {
                name = _name;
                value = _value;
            }
        }
        [Serializable]
        public class Maintain
        {
            public string name;
            public string sponsor;
            public string[] receive;
            public string item;
            public string status;
            public string[] record;
            public Maintain() { }
            public Maintain(string _name, string _sponsor, string[] _receive, string _item, string _status, string[] _record)
            {
                name = _name;
                sponsor = _sponsor;
                receive = _receive;
                item = _item;
                status = _status;
                record = _record;
            }
        }
        [Serializable]
        public class SystemMsg
        {
            public List<Floor> systemtype;
        }
        [Serializable]
        public class Floor
        {
            public string name;
            public List<string> off;
            public List<string> open;
            public List<EMP> emp;
            public Floor()
            {
                off = new List<string>();
                open = new List<string>();
                emp = new List<EMP>();
            }
        }
        [Serializable]
        public class EMP
        {
            public string name;
            public List<string> id;
            public List<SystemType> type;
            public EMP()
            {
                id = new List<string>();
                type = new List<SystemType>();
            }

        }
        [Serializable]
        public class SystemType
        {
            public string name;
            public List<SystemName> system;
            public List<string> id;
            public SystemType()
            {
                id = new List<string>();
                system = new List<SystemName>();
            }
        }
        [Serializable]
        public class SystemName
        {
            public string name;
            public List<string> id;
            public SystemName()
            {
                id = new List<string>();
            }
        }

        [Serializable]
        public class SystemJsonList
        {
            public List<SystemJson> shui;
            public List<SystemJson> feng;
            public List<SystemJson> dian;
            public SystemJsonList()
            {
                shui = new List<SystemJson>();
                feng = new List<SystemJson>();
                dian = new List<SystemJson>();
            }
        }
        [Serializable]
        public class SystemJson//干路系统类
        {
            public string code;
            public string name;
            public List<string> objid;
            public SystemJson()
            {
                objid = new List<string>();
            }
        }
        [Serializable]
        public class RelationPath
        {
            public string code;
            public string pahtname;
            public string kgname;
            public List<string> objID;
            public List<string> on_offID;
            public RelationPath()
            {
                objID = new List<string>();
                on_offID = new List<string>();
            }
        }
        [Serializable]
        public class Relation
        {
            public string relationCode;
        }





        #endregion

        class Dictionaries
        {
            #region  FBX字典
            private static Dictionary<string, string> fbxmodel;
            public static Dictionary<string, string> Fbxmodel
            {
                get
                {
                    if (fbxmodel == null)
                    {
                        fbxmodel = new Dictionary<string, string>();
                        TextAsset ta = Resources.Load<TextAsset>("Config/FBXjson");
                        FBXJson jsonObject = JsonUtility.FromJson<FBXJson>(ta.text);
                        foreach (FBXinfo info in jsonObject.infoList)
                        {
                            fbxmodel.Add(info.name, info.path);
                        }
                    }
                    return fbxmodel;
                }
                set
                {
                    fbxmodel = value;
                }
            }
            private static Dictionary<string, Dictionary<string, Message>> _fbxmsgDic;
            public static Dictionary<string, Dictionary<string, Message>> fbxmsgDic
            {
                get
                {
                    if (_fbxmsgDic==null)
                    {
                        _fbxmsgDic = new Dictionary<string, Dictionary<string, Message>>();
                        foreach (var item in Fbxmodel.Keys)
                        {
                            TextAsset ta = Resources.Load<TextAsset>("Config/"+ item);
                            if (ta != null)
                            {
                                Dictionary<string, Message> msg = new Dictionary<string, Message>();
                                MessageJson jsonObject = JsonUtility.FromJson<MessageJson>(ta.text);
                                for (int i = 0; i < jsonObject.message.Count; i++)
                                {
                                    if (!msg.ContainsKey(jsonObject.message[i].key))
                                    {
                                        Message _msg = new Message();
                                        _msg = jsonObject.message[i];
                                        msg.Add(jsonObject.message[i].key, _msg);
                                    }
                                }
                                _fbxmsgDic.Add(item,msg);
                            }
                        }
                    }
                    return _fbxmsgDic;
                }
                set
                {
                    _fbxmsgDic = value;
                }
            }
            private static Dictionary<string,  Floor> _systemmsg;
            public static Dictionary<string, Floor> systemmsg
            {
                get
                {
                    if (_systemmsg==null)
                    {
                        _systemmsg = new Dictionary<string, Floor>();
                        TextAsset ta = Resources.Load<TextAsset>("Config/SystemMsg");
                        if (ta != null)
                        {
                            SystemMsg jsonObject = JsonUtility.FromJson<SystemMsg>(ta.text);
                            for (int i = 0; i < jsonObject.systemtype.Count; i++)
                            {
                                if (!_systemmsg.ContainsKey(jsonObject.systemtype[i].name))
                                {
                                    Floor floor = new Floor();
                                    floor = jsonObject.systemtype[i];
                                    _systemmsg.Add(floor.name, floor);
                                }
                            }
                        }
                    }
                    return _systemmsg;
                }
                set
                {
                    _systemmsg = value;
                }
            }
            #region 内部类里面就一个链表容器,用来配合解析
            [Serializable]
            class FBXJson
            {
                public List<FBXinfo> infoList;
            }
            [Serializable]
          public  class MessageJson
            {
                public List<Message> message;
            }
            [Serializable]
            public class SystemJsonone
            {
                public List<SystemJsonList> json;
            }
            [Serializable]
            public class relationPathJson
            {
                public List<RelationPath> path;
            }
            [Serializable]
            public class RelationJson
            {
                public List<Relation> relation;
            }
            #endregion
            #endregion
            #region FBX所有对象集合
            private static Dictionary<string, SingleObject> singleObject;
            public static Dictionary<string, SingleObject> SingleObject
            {
                get
                {
                    if (singleObject == null)
                    {
                        singleObject = new Dictionary<string, SingleObject>();
                    }
                    return singleObject;
                }
                set
                {
                    singleObject = value;
                }
            }
            public static Dictionary<string, GameObject> FBXObject=new Dictionary<string, GameObject>();

            #endregion

            private static List<SystemJsonList> _sysjson;
            public static List<SystemJsonList> sysjson
            {
                get {
                    if (_sysjson==null)
                    {
                        _sysjson = new List<SystemJsonList>();
                        TextAsset ta = Resources.Load<TextAsset>("Config/SystemPath");
                        if (ta != null)
                        {
                            SystemJsonone jsonObject = JsonUtility.FromJson<SystemJsonone>(ta.text);
                            foreach (var item in jsonObject.json)
                            { 
                                _sysjson.Add(item);
                            }
                           
                        }
                    }
                    return _sysjson;
                }
                set
                {
                    _sysjson = value;
                }
            }

            private static List<RelationPath> _realtionPath;
            public static List<RelationPath> relationpath
            {
                get
                {
                    if (_realtionPath==null)
                    {
                            //_realtionPath = new List<RelationPath>();
                        //if (!ES2.Exists("RelationPath.config"))
                        //{
                        //    ES2.Save(_realtionPath, "RelationPath.config");
                        //    _realtionPath = ES2.LoadList<RelationPath>( "RelationPath.config?tag=name");
                        //}
                        //else
                        //_realtionPath = ES2.LoadList<RelationPath>("RelationPath.config?tag=name");
                        _realtionPath = new List<RelationPath>();
                        TextAsset ta = Resources.Load<TextAsset>("Config/RelationPath");
                        if (ta != null)
                        {
                            relationPathJson json = JsonUtility.FromJson<relationPathJson>(ta.text);
                            foreach (var item in json.path)
                            {
                                _realtionPath.Add(item);
                            }
                        }
                    }
                    return _realtionPath;
                }
                set
                {
                    _realtionPath = value;
                }
            }

            private static List<Relation> _realtion;
            public static List<Relation> realtion
            {
                get {
                    if (_realtion!=null)
                    {
                        if (_realtion.Count==0)
                        {
                            _realtion = null;
                        }
                    }
                    if (_realtion==null)
                    {
                        _realtion = new List<Relation>();
                        //if (!ES2.Exists("Realtion.config"))
                        //{
                        //    ES2.Save(_realtion, "Realtion.config");
                        //    _realtion = ES2.LoadList<Relation>("Realtion.config?tag=name");
                        //}
                        //else
                        //    _realtion = ES2.LoadList<Relation>("Realtion.config?tag=name");
                        TextAsset ta = Resources.Load<TextAsset>("Config/Relation");
                        if (ta != null)
                        {
                            RelationJson json = JsonUtility.FromJson<RelationJson>(ta.text);
                            foreach (var item in json.relation)
                            {
                                _realtion.Add(item);
                            }
                        }
                    }
                    return _realtion;
                }
                set
                {
                    _realtion = value;
                }
            }
            public static Dictionary<string, Material> _dictionary;
            public static Dictionary<string, Material> dictionary
            {
                get
                {
                    if (_dictionary == null)
                    {
                        Material[] matLists=ObjManager.objManager.materials;
                        _dictionary = new Dictionary<string, Material>();
                        _dictionary.Add("AHU - 顶出 OA(KC)L1-A-01", matLists.First(s => s.name == "黄色"));
                        _dictionary.Add("HY_插接头 标准", matLists.First(s => s.name == "黄色"));
                        _dictionary.Add("HYHS_DJDC_CGBB_2_2015_1.01 2层吊架", matLists.First(s => s.name == "吊架"));
                        _dictionary.Add("M_管接头 - 螺纹 - 可锻铸铁 喷淋-螺纹", matLists.First(s => s.name == "钢板红色烤漆"));
                        _dictionary.Add("T 形三通 - 常规1 标准", matLists.First(s => s.name == "橙色"));
                        _dictionary.Add("T 形三通 - 常规2 标准 2", matLists.First(s => s.name == "橙色"));
                        _dictionary.Add("T 形三通 - 常规2 标准", matLists.First(s => s.name == "橙色"));
                        _dictionary.Add("不燃玻璃钢-矩形 Y 形三通1 标准 2", matLists.First(s => s.name == "浅绿色"));
                        _dictionary.Add("不燃玻璃钢-矩形 Y 形三通2 标准 2", matLists.First(s => s.name == "浅绿色"));
                        _dictionary.Add("变径四通1 变经四通 2", matLists.First(s => s.name == "钢板红色烤漆"));
                        _dictionary.Add("变径管-常规 中水", matLists.First(s => s.name == "深蓝色"));
                        _dictionary.Add("四通 - 常规1 标准", matLists.First(s => s.name == "橙色"));
                        _dictionary.Add("圆形变径 - 角度 - 法兰 45 度", matLists.First(s => s.name == "墨绿色"));
                        _dictionary.Add("圆形弯头 - 弧形 - 法兰 标准", matLists.First(s => s.name == "墨绿色"));
                        _dictionary.Add("圆形接头 标准", matLists.First(s => s.name == "墨绿色"));
                        _dictionary.Add("圆形软管 软管 - 圆形", matLists.First(s => s.name == "钢板红色烤漆"));
                        _dictionary.Add("圆形风管 T 形三通", matLists.First(s => s.name == "浅绿色"));
                        _dictionary.Add("圆形风管 排烟", matLists.First(s => s.name == "墨绿色"));
                        _dictionary.Add("圆形风管 排风", matLists.First(s => s.name == "墨绿色"));
                        _dictionary.Add("圆形风管 接头", matLists.First(s => s.name == "绿色"));
                        _dictionary.Add("圆形风管软接 标准", matLists.First(s => s.name == "黄色"));
                        _dictionary.Add("天方地圆 - 角度 - 法兰 45 度", matLists.First(s => s.name == "黄色"));
                        _dictionary.Add("天方地圆 - 角度 - 法兰 60", matLists.First(s => s.name == "黄色"));
                        _dictionary.Add("天方地圆 - 角度 - 法兰 90", matLists.First(s => s.name == "黄色"));
                        _dictionary.Add("天方地圆 - 角度 - 法兰1 45 度", matLists.First(s => s.name == "黄色"));
                        _dictionary.Add("带配件的电缆桥架 强电合用桥架", matLists.First(s => s.name == "强电"));
                        _dictionary.Add("弯头 - 常规1 标准", matLists.First(s => s.name == "橙色"));
                        _dictionary.Add("弯头 - 常规2 标准 2", matLists.First(s => s.name == "橙色"));
                        _dictionary.Add("弯头-定度数 1.17°", matLists.First(s => s.name == "橙色"));
                        _dictionary.Add("弯头-定度数 1°", matLists.First(s => s.name == "橙色"));
                        _dictionary.Add("弯头-定度数 2°", matLists.First(s => s.name == "橙色"));
                        _dictionary.Add("弯头-定度数 3°", matLists.First(s => s.name == "钢板红色烤漆"));
                        _dictionary.Add("槽式_三通_水平等高 桥架", matLists.First(s => s.name == "强电"));
                        _dictionary.Add("槽式_弯通_水平等径 01E", matLists.First(s => s.name == "强电"));
                        _dictionary.Add("槽式_弯通_水平等径 02E", matLists.First(s => s.name == "强电"));
                        _dictionary.Add("电线", matLists.First(s => s.name == "强电"));
                        _dictionary.Add("风机配电箱", matLists.First(s => s.name == "强电"));
                        _dictionary.Add("槽式电缆桥架垂直等径上弯通 强电合用桥架", matLists.First(s => s.name == "强电"));
                        _dictionary.Add("槽式电缆桥架垂直等径下弯通 强电合用桥架", matLists.First(s => s.name == "强电"));
                        _dictionary.Add("槽式电缆桥架异径接头 强电合用桥架", matLists.First(s => s.name == "强电"));
                        _dictionary.Add("槽式电缆桥架水平三通 强电合用桥架", matLists.First(s => s.name == "强电"));
                        _dictionary.Add("槽式电缆桥架水平四通 强电合用桥架", matLists.First(s => s.name == "强电"));
                        _dictionary.Add("槽式电缆桥架水平弯通 强电合用桥架", matLists.First(s => s.name == "强电"));
                        _dictionary.Add("槽式电缆桥架活接头 强电合用桥架", matLists.First(s => s.name == "强电"));
                        _dictionary.Add("活接头_矩形 订制标准", matLists.First(s => s.name == "黄色"));
                        _dictionary.Add("消声器-ZF阻抗复合式 1.0M", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("消声器-ZF阻抗复合式 1.5M", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("消防箱1800-700 1800 x 700mm", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("混流风机 EA(VIP)L1-A-09a", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("混流风机 SE(KC)L1-A-01", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("混流风机 SE(VIP)L1-A-01", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("混流风机 SE(VIP)L1-A-03", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("混流风机 SE(VIP)L1-A-06", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("混流风机 SP(AT)A-L1-04", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("混流风机1 EA(VIP)L1-A-09a 2", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("混流风机1 SE(VIP)L1-A-06", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("混流风机2 SE(VIP)L1-A-06", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("直角出风风机 EA(SU)L2-A-04", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("矩形 T 形三通 - 斜接 - 法兰 标准", matLists.First(s => s.name == "浅绿色"));
                        _dictionary.Add("矩形 T 形三通 - 斜接 - 法兰1 标准", matLists.First(s => s.name == "浅绿色"));
                        _dictionary.Add("矩形 T 形三通 - 顶对齐 - 法兰 标准", matLists.First(s => s.name == "浅绿色"));
                        _dictionary.Add("矩形 Y 形三通 - 弧形 - 法兰 标准", matLists.First(s => s.name == "浅绿色"));
                        _dictionary.Add("矩形 Y 形三通 - 弧形 - 法兰1 标准 2", matLists.First(s => s.name == "浅绿色"));
                        _dictionary.Add("矩形 Y 形三通 - 弧形 - 法兰2 标准", matLists.First(s => s.name == "浅绿色"));
                        _dictionary.Add("矩形 Y 形三通 - 弯曲 - 法兰 标准", matLists.First(s => s.name == "浅绿色"));
                        _dictionary.Add("矩形变径管 - 角度 - 法兰 15 度", matLists.First(s => s.name == "浅绿色"));
                        _dictionary.Add("矩形变径管 - 角度 - 法兰 45 度", matLists.First(s => s.name == "浅绿色"));
                        _dictionary.Add("矩形变径管 - 角度 - 法兰 60 度", matLists.First(s => s.name == "浅绿色"));
                        _dictionary.Add("矩形变径管 - 角度 - 法兰 75 度", matLists.First(s => s.name == "浅绿色"));
                        _dictionary.Add("矩形变径管 - 角度 - 法兰 90度", matLists.First(s => s.name == "浅绿色"));
                        _dictionary.Add("矩形变径管 - 角度 - 法兰 105 度", matLists.First(s => s.name == "浅绿色"));
                        _dictionary.Add("矩形四通 - 弧形 - 法兰 标准", matLists.First(s => s.name == "黄色"));
                        _dictionary.Add("矩形四通 - 弧形 - 法兰1 标准", matLists.First(s => s.name == "黄色"));
                        _dictionary.Add("矩形弯头 - 半径 - 法兰 0.9 W", matLists.First(s => s.name == "黄色"));
                        _dictionary.Add("矩形弯头 - 直角 - 法兰 标准", matLists.First(s => s.name == "黄色"));
                        _dictionary.Add("矩形风管 镀锌钢管-空调系统", matLists.First(s => s.name == "黄色"));
                        _dictionary.Add("矩形风管 镀锌钢管-防排烟", matLists.First(s => s.name == "墨绿色"));
                        _dictionary.Add("矩形风管软接 矩形风管软接", matLists.First(s => s.name == "墨绿色"));
                        _dictionary.Add("管接头 - 常规1 标准", matLists.First(s => s.name == "天蓝色"));
                        _dictionary.Add("管接头1 标准 3", matLists.First(s => s.name == "橙色"));
                        _dictionary.Add("管道类型 PVCU-污、废水", matLists.First(s => s.name == "褐色"));
                        _dictionary.Add("管道类型 不锈钢-冷热水", matLists.First(s => s.name == "天蓝色"));
                        _dictionary.Add("管道类型 内外壁热镀锌钢管-压力排水", matLists.First(s => s.name == "浅褐色"));
                        _dictionary.Add("管道类型 内外壁热镀锌钢管-消防", matLists.First(s => s.name == "钢板红色烤漆"));
                        _dictionary.Add("管道类型 热镀锌钢管-暖通", matLists.First(s => s.name == "天蓝色"));
                        _dictionary.Add("管道隔热层 橡塑保温棉", matLists.First(s => s.name == "玻璃"));
                        _dictionary.Add("过渡件 - 常规1 标准", matLists.First(s => s.name == "橙色"));
                        _dictionary.Add("过渡件1 标准 2", matLists.First(s => s.name == "橙色"));
                        _dictionary.Add("通用静压箱 700x1400x1000 2", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("通用静压箱 2500x2500x800", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("静压箱_矩形-消声 静压箱_矩形-消声", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("风机 两边可调1 EA(0)L1-A-01", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("风机 两边可调1 EA(SU)L1-A-01", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("风机 两边可调1 EA(SU)L1-A-02", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("风机 两边可调1 EA(SU)L1-A-05", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("风机 两边可调1 EA(VIP)L1-A-26b", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("风机 两边可调1 EA/EG(EL)(SL1A01(1-1))", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("风机 两边可调1 EA/EG(EL)(SL1E108(1-2))", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("风机 两边可调1 EG(EL)UL1A01(1-1)", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("风机 两边可调能用 SA(KC)L1-A-01", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("风机盘管 - 卧式暗装 - 双管式 - 背部回风 - 右接 1850 W 2", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("风机盘管 - 卧式暗装 - 双管式 - 背部回风 - 右接 1850 W", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("风机盘管 类型 1", matLists.First(s => s.name == "铝"));
                        _dictionary.Add("风管软接 风管软接", matLists.First(s => s.name == "黄色"));
                        _dictionary.Add("风管隔热层 纤维玻璃", matLists.First(s => s.name == "玻璃"));
                    }
                    return _dictionary;
                }
                set
                {
                    _dictionary = value;
                }
            }
        }


    }
    /// <summary>
    /// 枚举集
    /// </summary>
    namespace Enmu
    {
        /// <summary>
        /// shader参数类型
        /// </summary>
        public enum ShaderType
        {
            _float,
            _int,
            _Color,
            _Color32,
            _Texture,
            _Texture2D,
            _Texture3D,
        }
        public enum EventButon
        {
            singleEvent,
            pluralEvent,
        }
        public enum buttonStyle
        {
            color,
            sprite,
            scale,
            animation
        }
        public enum buttonStatus
        {
            state,
            dynamic
        }
        public enum RelationType
        {
            系统,
            干路
        }
    }
    /// <summary>
    /// 自定义对象集
    /// </summary>
    namespace Custom
    {
        using UnityEngine;
        using Extensions;
        using System.Collections.Generic;
        using Data;
        using System.Threading;
        using HighlightingSystem;
        /// <summary>
        /// FBX单个构建对象
        /// </summary>
        public  class SingleObject:MonoBehaviour
        {
            /// <summary>
            /// 对象自身
            /// </summary>
            public GameObject go;
            /// <summary>
            /// 自身网格
            /// </summary>
            public MeshFilter mesh;
            /// <summary>
            /// 自身网格碰撞
            /// </summary>
            public MeshCollider collider;
            /// <summary>
            /// 高亮控件
            /// </summary>
            public Highlighter highlig;
            /// <summary>
            /// 自身携带的材质
            /// </summary>
            public Material material;
            /// <summary>
            /// 默认颜色
            /// </summary>
            public Color color;
            /// <summary>
            /// 自身的shder
            /// </summary>
            public Shader shader;
            /// <summary>
            /// 初始坐标
            /// </summary>
            public Vector3 point;
            [SerializeField]
            public Data.Message msg;
            public SingleObject() { }
            public SingleObject(GameObject obj)
            {
                go = obj;
                mesh = obj.GetComponent<MeshFilter>();
                if (obj.GetComponent<MeshCollider>())
                    collider = obj.GetComponent<MeshCollider>();
                else
                    collider = obj.AddComponent<MeshCollider>();
                material = obj.GetComponent<MeshRenderer>().material;
                //if (material != null)
                //    shader = material.shader;
                //point= mesh.mesh.GenerateRandomPoint();
            }
            public void SetSingleObject(GameObject obj,string patr)
            {
                go = obj;
                obj.layer = LayerMask.NameToLayer("Mode");
                collider = obj.GetComponent<MeshCollider>();
                if (collider == null)
                {
                    collider = obj.AddComponent<MeshCollider>();
                    material = obj.GetComponent<MeshRenderer>().material;
                    string nam = obj.name.GetName();
                    if (Dictionaries.dictionary.ContainsKey(nam))
                    {
                        Material matName = Dictionaries.dictionary.GetKeyValue<string, Material>(nam);
                        material = matName;
                        obj.GetComponent<MeshRenderer>().material = matName;
                    }
                    highlig = obj.AddComponent<HighlightingSystem.Highlighter>();
                    point = obj.transform.position;
                }
                try
                {
                    if (patr != "JDAL1" && patr != "AWAL1")
                        return;
                    Dictionaries.SingleObject.Add(obj.name.GetID(), this);
                }
                catch (System.Exception e)
                {
                    print(e);
                }
                //if (!obj.name.Contains("AW"))
                //    obj.SetActive(false);
            }
            //bool kongzhi = true;
            //private void Update()
            //{
            //    if (!kongzhi)
            //        return;
            //    if (go != null)
            //    {
            //        string key = go.name.Split('@')[0];
            //        Dictionary<string, Message> mesdic/* = Dictionaries.fbxmsgDic.GetKeyValue<string, Dictionary<string, Message>>(key)*/;
            //        Base.Data.Dictionaries.fbxmsgDic.TryGetValue(key, out mesdic);
            //        Dictionary<string, Message> mesdic = Dictionaries.fbxmsgDic.GetKeyValue<string, Message>(key);
            //        msg = mesdic.GetKeyValue<string, Message>(go.name.Split('@')[1]);
            //    }
            //    if (msg != null)
            //        kongzhi = false;
            //}
        }
        /// <summary>
        /// shader参数类
        /// </summary>
        public class ShaderCondition
        {
            public Enmu.ShaderType _type;
            public string _Key;
            public object _objerct;
            /// <summary>
            /// shader条件类
            /// </summary>
            /// <param name="type">参数类型</param>
            /// <param name="key">shader修改字段名字</param>
            /// <param name="obj">修改的值</param>
            public ShaderCondition(Enmu.ShaderType type, string key, object obj)
            {
                _type = type;
                _Key = key;
                _objerct = obj;
            }
        }
        /// <summary>
        /// SQL条件类
        /// </summary>
        public class SqlAnd
        {
            public string key;
            public string value;
            public SqlAnd(string _key, string _value)
            {
                key = _key;
                value = _value;
            }
        }
    }
    /// <summary>
    /// 扩展集
    /// </summary>
    namespace Extensions
    {
        using UnityEngine;
        using Enmu;
        using System.Collections.Generic;
        using System.Linq;
        using System;
        using System.Threading;
        using UnityEngine.UI;
        using UnityEngine.Events;
        /// <summary>
        /// 扩展类
        /// </summary>
        static class Extensions
        {
            public static string GetID(this string name)
            {
                if (name.Contains("["))
                    return name.Split('[')[1].Split(']')[0];
                else
                    return "";
            }
            public static string GetName(this string name)
            {
                if (name.Contains("["))
                    return name.Split('[')[0].TrimEnd();
                else
                    return "";
            }
            /// <summary>
            /// 设置shader
            /// </summary>
            /// <param name="sobj">singleObject</param>
            /// <param name="shaderPath">路径</param>
            /// <param name="shader">条件数组</param>
            public static void SetShader(this Custom.SingleObject sobj, string shaderPath, Custom.ShaderCondition[] shader)
            {
                    Material mater = sobj.material;
                    mater.shader = Shader.Find(shaderPath);
                    foreach (var item in shader)
                    {
                        switch (item._type)
                        {
                            case ShaderType._float:
                                mater.SetFloat(item._Key, (float)item._objerct);
                                break;
                            case ShaderType._int:
                                mater.SetInt(item._Key, (int)item._objerct);
                                break;
                            case ShaderType._Color:
                                mater.SetColor(item._Key, (Color)item._objerct);
                                break;
                            case ShaderType._Color32:
                                mater.SetColor(item._Key, (Color32)item._objerct);
                                break;
                            case ShaderType._Texture:
                                mater.SetTexture(item._Key, (Texture)item._objerct);
                                break;
                            case ShaderType._Texture2D:
                                mater.SetTexture(item._Key, (Texture2D)item._objerct);
                                break;
                            case ShaderType._Texture3D:
                                mater.SetTexture(item._Key, (Texture3D)item._objerct);
                                break;
                        }
                    }
                
            }
            public static void SetShader(this Custom.SingleObject sobj)
            {
                sobj.material.shader = sobj.shader;
            }
            public static void SetHighlighter(this Custom.SingleObject sobj, Color color)
            {
                sobj.highlig.ConstantOn(color);
            }
            public static void SetHighlighter(this Custom.SingleObject sobj)
            {
                sobj.highlig.ConstantOff();
            }
            static public EventTriggerListener Get(this Transform transform, PluralButton plural=null)
            {
                EventTriggerListener listener = transform.GetComponent<EventTriggerListener>();
                if (listener == null)
                    listener = transform.gameObject.AddComponent<EventTriggerListener>();
                switch (listener.eventbut)
                {
                    case EventButon.singleEvent:
                        break;
                    case EventButon.pluralEvent:
                        if (plural != null)
                        {
                            listener.plural = plural;
                        }
                        break;
                }



                return listener;

            }
            public static void Center(this Transform trans)
            {
                Function.Center(trans);
            }
            /// <summary>
            /// 获取字典value
            /// </summary>
            /// <typeparam name="T1">Key</typeparam>
            /// <typeparam name="T2">Value</typeparam>
            /// <param name="dic"></param>
            /// <param name="key">key</param>
            /// <returns></returns>
            public static T2 GetKeyValue<T1, T2>(this Dictionary<T1, T2> dic, T1 key)
            {
                T2 t2;
                dic.TryGetValue(key,out t2);
                return t2;
            }
            /// <summary>
            /// 设置UIText内容
            /// </summary>
            /// <param name="trans"></param>
            /// <param name="text"></param>
            public static void SetText(this Transform trans,string text)
            {
                trans.GetComponent<Text>().text = text;
            }
            public static void SetInputText(this Transform tran, string text)
            {
                tran.GetComponent<InputField>().text = text;
            }
            public static string GetText(this Transform tran)
            {
                string text= tran.GetComponent<Text>().text;
                return text;
            }
            /// <summary>
            /// 设置脚本状态扩展
            /// </summary>
            /// <typeparam name="T">脚本类型</typeparam>
            /// <param name="trans">携带对象</param>
            /// <param name="enabled">状态</param>
            /// <returns></returns>
            public static Transform SetEnable<T>(this Transform trans, bool enabled) where T : Behaviour
            {
                if (trans)
                {
                    var comp = trans.GetComponent<T>();
                    if (comp)
                    {
                        comp.enabled = enabled;
                    }
                }
                return trans;
            }
            public static void SetToggleOnClick(this Transform tans, UnityAction<bool> action, bool _ison = false)
            {
                Toggle toggle = tans.GetComponent<Toggle>();
                toggle.isOn = _ison;
                toggle.onValueChanged.AddListener(delegate(bool ison){ action(ison); });
            }
            public static Transform InstanUI(this UnityEngine.Object obj, Transform parent)
            {
                GameObject go = UnityEngine.Object.Instantiate(obj) as GameObject;
                go.SetActive(true);
                go.transform.parent = parent;
                go.transform.localPosition = Vector3.zero;
                go.transform.localScale = Vector3.one;
                return go.transform;
            }

        }
        class Function
        { 
            /// <summary>
            /// 根据函数名调用函数并返回自定义类型T
            /// </summary>
            /// <typeparam name="T">返回类型</typeparam>
            /// <typeparam name="T1">函数存在类</typeparam>
            /// <param name="name">函数名字</param>
            /// <returns></returns>
            public static T FindFunctionName<T, T1>(string name, object[] obj)
            {
                T t = default(T);
                T1 t1 = default(T1);
                Type type = typeof(T1);
                try
                {
                    if ((T)type.GetMethod(name).Invoke(t1, obj) != null)
                    {
                        t = (T)type.GetMethod(name).Invoke(t1, obj);
                    }
                }
                catch (Exception e)
                {

                    UnityEngine.Debug.Log(name);
                    UnityEngine.Debug.LogError(e);
                }

                return t;
            }
            /// <summary>
            /// 设置组合模型中心点
            /// </summary>
            /// <param name="parent"></param>
            public  static void Center(Transform parent)
            {
                Vector3 postion = parent.position;
                Quaternion rotation = parent.rotation;
                Vector3 scale = parent.localScale;
                parent.position = Vector3.zero;
                parent.rotation = Quaternion.Euler(Vector3.zero);
                parent.localScale = Vector3.one;
                Vector3 center = Vector3.zero;
                Renderer[] renders = parent.GetComponentsInChildren<Renderer>();
                foreach (Renderer child in renders)
                {
                    center += child.bounds.center;
                }
                center /= parent.GetComponentsInChildren<Transform>().Length;
                Bounds bounds = new Bounds(center, Vector3.zero);
                foreach (Renderer child in renders)
                {
                    bounds.Encapsulate(child.bounds);
                }

                parent.position = postion;
                parent.rotation = rotation;
                parent.localScale = scale;

                foreach (Transform t in parent)
                {
                    t.position = t.position - bounds.center;
                }
                parent.transform.position = bounds.center + parent.position;
            }
        }
        /// <summary>
        /// 线程池
        /// </summary>
        class Loom: MonoBehaviour
        {
            public static int maxThreads = 8;
            static int numThreads;

            private static Loom _current;
            private int _count;
            public static Loom Current
            {
                get
                {
                    Initialize();
                    return _current;
                }
            }

            void Awake()
            {
                _current = this;
                initialized = true;
            }

            static bool initialized;

            static void Initialize()
            {
                if (!initialized)
                {

                    if (!Application.isPlaying)
                        return;
                    initialized = true;
                    var g = new GameObject("Loom");
                    _current = g.AddComponent<Loom>();
                }

            }

            private List<Action> _actions = new List<Action>();
            public struct DelayedQueueItem
            {
                public float time;
                public Action action;
            }
            private List<DelayedQueueItem> _delayed = new List<DelayedQueueItem>();

            List<DelayedQueueItem> _currentDelayed = new List<DelayedQueueItem>();

            public static void QueueOnMainThread(Action action)
            {
                QueueOnMainThread(action, 0f);
            }
            public static void QueueOnMainThread(Action action, float time)
            {
                if (time != 0)
                {
                    lock (Current._delayed)
                    {
                        Current._delayed.Add(new DelayedQueueItem { time = Time.time + time, action = action });
                    }
                }
                else
                {
                    lock (Current._actions)
                    {
                        Current._actions.Add(action);
                    }
                }
            }

            public static Thread RunAsync(Action a)
            {
                Initialize();
                while (numThreads >= maxThreads)
                {
                    Thread.Sleep(1);
                }
                Interlocked.Increment(ref numThreads);
                ThreadPool.QueueUserWorkItem(RunAction, a);
                return null;
            }

            private static void RunAction(object action)
            {
                try
                {
                    ((Action)action)();
                }
                catch
                {
                }
                finally
                {
                    Interlocked.Decrement(ref numThreads);
                }

            }


            void OnDisable()
            {
                if (_current == this)
                {

                    _current = null;
                }
            }



            // Use this for initialization  
            void Start()
            {

            }

            List<Action> _currentActions = new List<Action>();

            // Update is called once per frame  
            void Update()
            {
                lock (_actions)
                {
                    _currentActions.Clear();
                    _currentActions.AddRange(_actions);
                    _actions.Clear();
                }
                foreach (var a in _currentActions)
                {
                    a();
                }
                lock (_delayed)
                {
                    _currentDelayed.Clear();
                    _currentDelayed.AddRange(_delayed.Where(d => d.time <= Time.time));
                    foreach (var item in _currentDelayed)
                        _delayed.Remove(item);
                }
                foreach (var delayed in _currentDelayed)
                {
                    delayed.action();
                }



            }
        }
    }
    
    
}
